Page({
	data: {
		floors: [
			{ id: 1, name: '北苑1栋' },
			{ id: 2, name: '北苑2栋' },
			{ id: 3, name: '北苑3栋' },
			{ id: 4, name: '南苑1栋' },
			{ id: 5, name: '南苑2栋' },
			{ id: 6, name: '南苑3栋' },
		],
		floor: 0,
		rooms: [
			{ id: 1, name: '101', floor_id: 1 },
			{ id: 2, name: '102', floor_id: 1 },
			{ id: 3, name: '103', floor_id: 1 },
			{ id: 4, name: '104', floor_id: 1 },
			{ id: 5, name: '105', floor_id: 1 },

			{ id: 6, name: '101', floor_id: 2 },
			{ id: 7, name: '102', floor_id: 2 },
			{ id: 8, name: '103', floor_id: 2 },
			{ id: 9, name: '104', floor_id: 2 },
			{ id: 10, name: '105', floor_id: 2 },

			{ id: 11, name: '101', floor_id: 3 },
			{ id: 12, name: '102', floor_id: 3 },
			{ id: 13, name: '103', floor_id: 3 },
			{ id: 14, name: '104', floor_id: 3 },
			{ id: 15, name: '105', floor_id: 3 },
		],
		room: 0,
		beds: [
			{ id: 1, name: '1号' },
			{ id: 2, name: '2号' },
			{ id: 3, name: '3号' },
			{ id: 4, name: '4号' },
			{ id: 5, name: '5号' },
			{ id: 6, name: '6号' },
		],
		bed: 0,
		appointed: false
	},

	onLoad() {
		const droms = wx.getStorageSync('drom')
		if (droms) {
			this.setData({
				appointed: true,
				floor: droms[0],
				room: droms[1],
				bed: droms[2],
			})
		}
	},

	handlePickerChange(e) {
		this.setData({
			[e.currentTarget.dataset.type]: e.detail.value
		})
	},

	formSubmit(e) {
		const { floors, floor, rooms, room, beds, bed } = this.data
		wx.showModal({
			title: '您预定的宿舍为',
			content: `${floors[floor].name} ${rooms[room].name}房 ${beds[bed].name}床`,
			showCancel: true,
			success(res) {
				if (res.confirm) {
					wx.setStorage({
						key: 'drom',
						data: [floor, room, bed],
						success(res) {
							wx.showToast({
								title: '预定成功',
							})
						}
					})
				}
			}
		})
	}
})